<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Apply_model extends CI_Model{
	
	var	$table				=	"prices";
	var $table_country		=	"country";
	var $table_customers	=	"customers";
	var	$table_apply		=	"apply";
	var $table_session		=	"session";
	var $table_invoice		=	"invoice";
	
	function __construct(){
        parent::__construct(); 
    }
	
	
	function get_price($type_visa){
		$option					=	$this->db->where('type_visa', $type_visa)
											 ->where('status', 'active')
							 		 		 ->get($this->table)
							 	 			 ->row_array();
		if(!empty($option)){
			return $option;
		}
		return false;
	}
	
	
	function get_type_of_visa(){
		$type	=	$this->db->where('status','active' )
							 ->get($this->table)
							 ->result();
		if(!empty($type)){
			return $type;
		}
		return false;
	}
	
	
	
	function get_country(){
		$country	=	$this->db->select(array('id', 'name'))
								 ->where('active', 'yes')
								 ->get($this->table_country)
								 ->result();
		if(!empty($country)){
			return	$country;
		}
		return false;
	}

	
	function save_session($data){
		$this->db->insert($this->table_session, $data);
		return $this->db->insert_id();
	}
	
	function add_contact($contact_info = array()){
		$this->db->insert($this->table_customers, $contact_info);
		return $this->db->insert_id();
	}
	
	function update_customer_info($cus_id, $info = array()){
		#not update following information.
		unset($info['name']);
		unset($info['email']);
		unset($info['phone']);
		unset($info['purpose']);
		unset($info['message']);
		unset($info['amount_visa']);
		unset($info['type_visa']);
		unset($info['services']);
		unset($info['date_arrival']);
		unset($info['date_exit']);
		unset($info['arrival_port']);
		unset($info['nationality']);
		unset($info['flight_number']);
		
		#execute updating.
		$this->db->where('id', $cus_id)
				 ->update($this->table_customers, $info);
	}
	
	function add_applicants($applicant_info = array()){
		$this->db->insert($this->table_apply, $applicant_info);
	}
	
	
	function get_apply_info($customer_id){
		$apply	=	$this->db->select()
							 ->where('customer_id', $customer_id)
							 ->get($this->table_apply)
							 ->result();
		if(!empty($apply)){
			return $apply;
		}
		return false;
	}
	
	
	function get_session_info($cus_id){
		$cus	=	$this->db->select('id, purpose, number_visa, type_visa, rush_services')
							 ->where('id', $cus_id)
							 ->get($this->table_session)
							 ->row_array();
		if(!empty($cus)){
			return $cus;
		}
		return false;
	}
	
	
	function get_customers_info($customer_id){
		$customers	=	$this->db->select()
								 ->where('id', $customer_id)
								 ->get($this->table_customers)
								 ->row_array();
		if(!empty($customers)){
			return $customers;
		}
		return false;
	}
	
	function contact_info_changing($customer_id, $data = array()){
		#not update following information.
		unset($data['name']);
		unset($data['email']);
		unset($data['phone']);
		unset($data['purpose']);
		unset($data['message']);
		unset($data['amount_visa']);
		unset($data['type_visa']);
		if($data['services'] == ""){
			unset($data['services']);
		}
		if($data['arrival_port'] == ""){
			unset($data['arrival_port']);
		}
		unset($data['nationality']);
		unset($data['airfast_track']);
		unset($data['carpick_up']);
		unset($data['tour_booking']);
		unset($data['hotel_booking']);
		unset($data['toat_prices']);
		unset($data['pay_method']);
		unset($data['status']);
		
		$this->db->where('id', $customer_id)
				 ->update($this->table_customers, $data);
	}
	
	function apply_info_changing($apply_id, $data = array()){
		#not update following information.
		unset($data['customer_id']);
		if($data['full_name'] 	== ""){unset($data['full_name']);}
		if($data['passport'] 	== ""){unset($data['passport']);}
		if($data['expiration'] 	== ""){unset($data['expiration']);}
		if($data['nationality'] == ""){unset($data['nationality']);}
		if($data['birth_date'] 	== ""){unset($data['birth_date']);}
		if($data['gender'] 		== ""){unset($data['gender']);}
		
		$this->db->where('id', $apply_id)
				 ->update($this->table_apply, $data);
	}
	
	
	function make_invoice($invoice){
		$this->db->insert($this->table_invoice, $invoice);
				 
	}
	
}

/* End of file apply_model.php */
/* Location: ./application/models/apply_model.php */